<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/7
 * Time: 21:22
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\service\RecyclePaidMessage;
use app\api\validate\IDMustBePositiveInt;
use app\api\model\Order as OrderModel;
use app\lib\enum\OrderStatusEnum;
use app\lib\enum\OrderTypeEnum;
use app\lib\Exception\OrderException;
use app\lib\Exception\ParameterException;

class Message extends BaseController
{
    protected $beforeActionList = [
        'checkSuperScope' => ['only' => 'recyclePaid']
    ];


    // recycle order 打款之后 发送模版消息
    public function recyclePaid($id){
        (new IDMustBePositiveInt())->toCheck();

        $order = OrderModel::get($id);

        if(!$order){
            throw new OrderException();
        }

        if($order->order_type != OrderTypeEnum::Recycle || $order->status != OrderStatusEnum::PAID){
        throw new ParameterException([
            'info' => '订单类型错误或订单状态错误'
        ]);
    }

        $recyclePaid = new RecyclePaidMessage();
        $recyclePaid->sendMsg($order);
    }
}